#!/bin/bash

function create_files() {
	: '
		ln -sf /data/data/com.zzvm/files/z/usr/glibc/lib/ld-linux-aarch64.so.1 ld.so
	'

	echo "正在创建必要的文件"
	(cd ${WBOXDIR}/usr/glibc/etc &&  ln -sf ../../etc/resolv.conf  ./resolv.conf)

	echo "调整文件夹权限"
	chown droidvm -R ${WBOXDIR}/usr/glibc
	chmod a+x     -R ${WBOXDIR}/usr/glibc
	chmod a+x		 ./ezapp/wbox/wbox.sh
	chmod +x         ${WBOXDIR}/usr/glibc/bin/box64
	chmod +x         ${WBOXDIR}/usr/glibc/${WBOX_WINE}/bin/{wine,wineserver}

	mkdir -p $WBOXDIR/usr/glibc/opt/package-manager 2>/dev/null


    echo "正在生成 wine-DPI设置文件"
	cat <<- EOF > $WBOXDIR/usr/glibc/opt/prefix/dpi.reg
		REGEDIT4

		[HKEY_CURRENT_USER\Software\Wine\Fonts\Replacements]
		"DFKai-SB"="WenQuanYi Micro Hei"
		"FangSong"="WenQuanYi Micro Hei"
		"KaiTi"="WenQuanYi Micro Hei"
		"Microsoft JhengHei"="WenQuanYi Micro Hei"
		"Microsoft YaHei"="WenQuanYi Micro Hei"
		"MingLiU"="WenQuanYi Micro Hei"
		"SimSun"="WenQuanYi Micro Hei"
		"PMingLiU"="WenQuanYi Micro Hei"
		"SimHei"="WenQuanYi Micro Hei"
		"SimKai"="WenQuanYi Micro Hei"
		"SimSun"="WenQuanYi Micro Hei"


		[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
		"Lucida Sans Unicode"="WenQuanYi Micro Hei"
		"Microsoft Sans Serif"="WenQuanYi Micro Hei"
		"MS Sans Serif"="WenQuanYi Micro Hei"
		"Tahoma"="WenQuanYi Micro Hei"
		"Tahoma Bold"="WenQuanYi Micro Hei"
		"SimSun"="WenQuanYi Micro Hei"
		"Arial"="WenQuanYi Micro Hei"
		"Arial Black"="WenQuanYi Micro Hei"

		[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Hardware Profiles\Current\Software\Fonts]
		"LogPixels"=dword:00000090
	EOF

    echo "正在生成驱动相关的文件"
	mkdir -p ${WBOXDIR}/gldriver 2>/dev/null
	echo "LINUX_GL_DRIVER_MODE='MESA.llvmpipe'"				> ${WBOXDIR}/gldriver/gldriver.llvmpipe.rc
	echo "LINUX_GL_DRIVER_CARD='全部GPU'"					>>${WBOXDIR}/gldriver/gldriver.llvmpipe.rc
	echo "LINUX_GL_DRIVER_INFO='纯软件运算，无硬件加速'"	>>${WBOXDIR}/gldriver/gldriver.llvmpipe.rc

	echo "LINUX_GL_DRIVER_MODE='MESA.virpipe'"				> ${WBOXDIR}/gldriver/gldriver.virgl.rc
	echo "LINUX_GL_DRIVER_CARD='全部GPU'"					>>${WBOXDIR}/gldriver/gldriver.virgl.rc
	echo "LINUX_GL_DRIVER_INFO='有硬件加速，但效率几无提升'">>${WBOXDIR}/gldriver/gldriver.virgl.rc

	echo "LINUX_GL_DRIVER_MODE='MESA.turnip'"				> ${WBOXDIR}/gldriver/gldriver.turnip.rc
	echo "LINUX_GL_DRIVER_CARD='骁龙系'"					>>${WBOXDIR}/gldriver/gldriver.turnip.rc
	echo "LINUX_GL_DRIVER_INFO='有硬件加速，效率极高'"		>>${WBOXDIR}/gldriver/gldriver.turnip.rc

    echo "正在将默认的图形驱动设置为 MESA.llvmpipe "
	cp -f ${WBOXDIR}/gldriver/gldriver.llvmpipe.rc ${WBOXDIR}/gldriver.rc


	echo "正在生成显卡驱动安装目录"
	mkdir -p ${ZZ_USER_HOME}/Desktop/显卡驱动  2>/dev/null
	tmpGLName="virgl turnip"
	for glname in ${tmpGLName}
	do
		cat <<- EOF > "${WBOXDIR}/gldriver/wbox-setup-${glname}.sh"
			#!/bin/bash
			cp -f ${WBOXDIR}/gldriver/gldriver.${glname}.rc   ${WBOXDIR}/gldriver.rc
			# wbox wineserver -k
			# sleep 5
			wbox setupgl
			sleep 5
			wbox info
		EOF
		chmod a+x "${WBOXDIR}/gldriver/wbox-setup-${glname}.sh"

		cat <<- EOF > "${ZZ_USER_HOME}/Desktop/显卡驱动/wbox-setup-${glname}.desktop"
			[Desktop Entry]
			Name=安装${glname}
			GenericName=安装${glname}
			Exec=${WBOXDIR}/gldriver/wbox-setup-${glname}.sh
			Terminal=true
			Type=Application
			Icon=/exbin/tools/zzswmgr/ezapp/wbox/wbox.png
		EOF

	done
	cat <<- EOF > "${ZZ_USER_HOME}/Desktop/显卡驱动/安装说明.txt"

		你可以在这个目录中安装适用于 wbox 的显卡驱动。
		
		要装哪一个，请参考下面的说明：
		=======================================
		 virgl: 它适用于所有的GPU，有硬件加速，但效率几无提升
		turnip: 仅适用于骁龙系GPU，有硬件加速，效率极高

	EOF
	cat <<- EOF > "${ZZ_USER_HOME}/Desktop/显卡驱动/常见错误.txt"

		error launching installer
		=======================================
		一般是因为 exe 文件所在的目录，wine 无权限访问
		处理办法：把exe文件挪个目录就好

	EOF
	cat <<- EOF > "${WBOXDIR}/gldriver/wbox-info.sh"
		#!/bin/bash
		wbox info > /tmp/wbox-info.txt
		gxmessage -title "wbox信息" -file /tmp/wbox-info.txt -center
	EOF
	chmod a+x "${WBOXDIR}/gldriver/wbox-info.sh"
	cat <<- EOF > "${ZZ_USER_HOME}/Desktop/显卡驱动/wbox-info.desktop"
		[Desktop Entry]
		Name=查看芯片信息
		GenericName=查看芯片信息
		Exec=${WBOXDIR}/gldriver/wbox-info.sh
		Terminal=false
		Type=Application
		Icon=/exbin/tools/zzswmgr/ezapp/wbox/wbox.png
	EOF
	cat <<- EOF > "${WBOXDIR}/gldriver/wbox-reset.sh"
		#!/bin/bash
		rm -rf ${WINE_HOME_P}
		gxmessage -title "wbox信息" "已删除wine主目录，下次运行wbox程序时会重新初始化" -center
	EOF
	chmod a+x "${WBOXDIR}/gldriver/wbox-reset.sh"

	tmpbmfile=${ZZ_USER_HOME}/.config/gtk-3.0/bookmarks
	mkdir -p ${ZZ_USER_HOME}/.config/gtk-3.0 2>/dev/null
	chmod 775 ${ZZ_USER_HOME}/.config/gtk-3.0
	grep "C盘"  ${tmpbmfile}
	if [ $? -ne 0 ]; then
		echo "file://${WINE_HOME_P}/drive_c C盘">> ${tmpbmfile}
	fi
	grep "Z盘"  ${tmpbmfile}
	if [ $? -ne 0 ]; then
		echo "file://${WBOXDIR} Z盘">> ${tmpbmfile}
	fi


}


# termux path to zzvm path, 处理结果保存在变量 ${ZPATH} 中
function tpath2zpath() {
	tmpstr=$1
	unset ZPATH
	if [[ "$tmpstr" == "" ]]; then
		return
	fi
	if [[ "$tmpstr" != *"com.termux/files"* ]]; then
		return
	fi

	dststr="/data/user/0/com.zzvm/files/z"

	srcstr1="/data/data/com.termux/files"
	srcstr2="/data/user/0/com.termux/files"
	if [[ "$tmpstr" == *"${srcstr1}"* ]]; then
		ZPATH=${tmpstr//${srcstr1}/\/data\/user\/0\/com.zzvm\/files\/z}
	elif [[ "$tmpstr" == *"${srcstr2}"* ]]; then
		ZPATH=${tmpstr//${srcstr2}/\/data\/user\/0\/com.zzvm\/files\/z}
	fi
}

# 返回值保存在 ${INTERPRETER} 变量中
function get_interpreter_from_str() {
	unset INTERPRETER
	if [[ "$fileinfo" == *", interpreter "* ]]; then
		INTERPRETER=${fileinfo##*interpreter }
		INTERPRETER=${INTERPRETER%%,*}
	fi
}

# 返回值保存在 ${RPATH} 变量中
function get_rpath_from_str() {
	unset RPATH
	if [[ "$elf_info" == *"Library rpath:"* ]]; then
		RPATH=`echo "$elf_info"|grep "Library rpath:"`
		RPATH=${RPATH##*"Library rpath: ["}
		RPATH=${RPATH%%"]"*}
	fi
}

# 返回值保存在 ${RUNPATH} 变量中
function get_runpath_from_str() {
	unset RUNPATH
	if [[ "$elf_info" == *"Library runpath:"* ]]; then
		RUNPATH=`echo "$elf_info"|grep "Library runpath:"`
		RUNPATH=${RUNPATH##*"Library runpath: ["}
		RUNPATH=${RUNPATH%%"]"*}
	fi
}


ELFPATH_LOG_ENABLED=${ELFPATH_LOG_ENABLED=0}
PATH_LOG_PATCH=/tmp/patch.log
# 在这个函数里面处理
function process_file() {
	i=$1

	fileinfo=`file $i 2>/dev/null`

	if [[ "$fileinfo" != *": ELF "* ]]; then
		# echo "跳过, 不是elf文件: $filename"
		return
	fi

	if [[ "$fileinfo" == *"relocatable"* ]]; then
		# echo "跳过, 不是动态库或可执行文件: $filename"
		return
	fi

	if [[ "$fileinfo" == *"statically linked"* ]]; then
		# echo "跳过, 不是动态库或可执行文件: $filename"
		return
	fi

	elf_info=`readelf -d $i 2>/dev/null`

	get_interpreter_from_str
	get_rpath_from_str
	get_runpath_from_str

	tpath2zpath "$INTERPRETER"
	newi=$ZPATH

	tpath2zpath "$RPATH"
	newr=$ZPATH

	tpath2zpath "$RUNPATH"
	newu=$ZPATH


	FORCELOG=0
	bdir=`dirname $i`
	if   [[ "$bdir" == "$WBOXDIR/usr/glibc"* ]]; then
		if   [[ "$bdir" == "$WBOXDIR/usr/glibc/bin"* ]]; then
			if [ "$RPATH" == "" ] && [ "$RUNPATH" == "" ]; then
				FORCELOG=1
				newr=${APP_INTERNAL_DIR}/z/usr/glibc/lib:${APP_INTERNAL_DIR}/z/usr/glibc/lib/x86_64-linux-gnu/
			fi
		fi
		# 	# newr="\$ORIGIN"
	# elif [ "$bdir" == "$WBOXDIR/usr/"* ]; then
	# 	newu=${APP_INTERNAL_DIR}/z/usr/lib
	# 	# 	newu="\$ORIGIN"
	fi


	command=""
	if [ "$newr" != "" ]; then
		# --force-rpath  这个参数是强制设置 rpath 的，但 rpath 已经被弃用，请尽量不要加这个参数！，即使用 runpath, 而非 rpath
		command+="--force-rpath --set-rpath ${newr} "
 	elif  [ "$newu" != "" ]; then
		command+="              --set-rpath ${newu} "
	fi

	if [ "$newi" != "" ]; then
		command+="--set-interpreter ${newi} "
	fi

	if [ $ELFPATH_LOG_ENABLED -ne 0 ] || [ $FORCELOG -eq 1 ]; then
		itemlen=80
		echo                                        "   当前文件: $i"
		printf "%-${itemlen}s %-${itemlen}s""\n"	"interpreter: ${INTERPRETER=-}"	"=> ${newi=-}"	# >> ${PATH_LOG_PATCH}
		printf "%-${itemlen}s %-${itemlen}s""\n"	"      rpath: ${RPATH=-}"		"=> ${newr=-}"	# >> ${PATH_LOG_PATCH}
		printf "%-${itemlen}s %-${itemlen}s""\n"	"    runpath: ${RUNPATH=-}"		"=> ${newu=-}"	# >> ${PATH_LOG_PATCH}
		echo										"   patchelf: $command"
		echo ""
	fi

	if [ "$command" != "" ]; then
		patchelf $command $i
		if [ $? -ne 0 ]; then echo "处理失败 $i"; fi
	fi
}

function wboxPatchElfFiles() {

	dirtopatch=$1
	if [ "$dirtopatch" == "" ]; then
		return
	fi

	for i in ${dirtopatch}/*; do
		process_file $i
	done

}


function doPatch_new() {
	
	patchelf --force-rpath \
	--set-rpath       ${APP_INTERNAL_DIR}/z/usr/glibc/lib \
	--set-interpreter ${APP_INTERNAL_DIR}/z/usr/glibc/lib/ld-linux-aarch64.so.1 \
	$WBOXDIR/usr/glibc/bin/box64

	# 字符串等长替换！
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/wine-9.3-vanilla-wow64/bin/wineserver
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/wine-9.3-vanilla-wow64/lib/wine/x86_64-unix/ntdll.so
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/bin/bash

	# 文件管理器路径汉字乱码处理：https://github.com/olegos2/mobox/issues/362
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/bin/locale
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/bin/localedef
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	$WBOXDIR/usr/glibc/bin/locale-gen
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	`realpath $WBOXDIR/usr/glibc/lib/libxcb.so`
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	`realpath $WBOXDIR/usr/glibc/lib/libc.so.6`
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	`realpath $WBOXDIR/usr/glibc/lib/libfontconfig.so`
	sed -i "s|/data/data/com.termux/files|/data/data/com.zzvm/files/z|g"	`realpath $WBOXDIR/usr/glibc/lib/libX11.so`




	# echo ""> ${PATH_LOG_PATCH}

	if [ "$QUICK_PATCH" != "1" ]; then
		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/lib
		WBOX_INTERPRT=
		WBOX_FORCERPT=

		echo "正在处理 glibc  (gnu    libc 系列的软件)"
		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/glibc/lib:${APP_INTERNAL_DIR}/z/usr/glibc/lib/x86_64-linux-gnu/
		WBOX_INTERPRT=${APP_INTERNAL_DIR}/z/usr/glibc/lib/ld-linux-aarch64.so.1
		WBOX_FORCERPT="--force-rpath"
		wboxPatchElfFiles $WBOXDIR/usr/glibc/bin
		# wbox_wine_elfheader_patch $WINE_PATH/bin	# 这个不需要
	fi

		echo "正在处理 glibc  (gnu    libc 系列的动态库)"
		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/lib
		WBOX_INTERPRT=
		WBOX_FORCERPT=
		wboxPatchElfFiles $WBOXDIR/usr/glibc/lib

	echo "patch 已完成"
}



# # old ==========================

# function old_wboxPatchElfFiles() {

# 	dirtopatch=$1
# 	if [ "$dirtopatch" == "" ]; then
# 		return
# 	fi

# 	for i in ${dirtopatch}/*; do
# 		file $i|grep ELF 2>&1 > /dev/null
# 		if [ $? -ne 0 ]; then
# 				continue
# 		fi

# 		filename=`basename $i`
# 		# echo "正在处理: $filename"

# 		# readelf -a  $i 2>&1 >/dev/null
# 		# readrlt=$?
# 		# if [ $readrlt -ne 0 ]; then
# 		# 	echo "跳过, 不是elf文件: $filename"
# 		# 	continue
# 		# fi

# 		elfinfo=`file $i 2>/dev/null`
		
# 		if [[ "$elfinfo" != *": ELF "* ]]; then
# 			echo "跳过, 不是elf文件: $filename"
# 			continue
# 		fi

# 		if [[ "$elfinfo" == *"relocatable"* ]]; then
# 			echo "跳过, 不是动态库或可执行文件: $filename"
# 			continue
# 		fi

# 		if [[ "$elfinfo" == *"statically linked"* ]]; then
# 			echo "跳过, 不是动态库或可执行文件: $filename"
# 			continue
# 		fi

# 		echo "$elfinfo"|grep "interpreter" 2>&1 > /dev/null
# 		if [ $? -eq 0 ]; then
# 			# echo "有interpreter"

# 			interpreter=${elfinfo##*interpreter}
# 			interpreter=${interpreter%%,*}
# 			# echo ${interpreter}

# 			if [ "${WBOX_INTERPRT}" != "" ]; then
# 				patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH} --set-interpreter ${WBOX_INTERPRT}   "$i"
# 				if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 			else
# 				patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH}                                      "$i"
# 				if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 			fi

# 		else
# 				# echo "无interpreter"
# 				patchelf ${WBOX_FORCERPT} --set-rpath "\$ORIGIN"  "$i"
# 				if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		fi
# 	done

# }

# function old_wboxPatchElfFiles_for_glibc_lib() {

# 	dirtopatch=$1
# 	if [ "$dirtopatch" == "" ]; then
# 		return
# 	fi

# 	for i in ${dirtopatch}/*; do
# 		file $i|grep ELF 2>&1 > /dev/null
# 		if [ $? -ne 0 ]; then
# 				continue
# 		fi

# 		filename=`basename $i`
# 		# echo "正在处理: $filename"

# 		# readelf -a  $i 2>&1 >/dev/null
# 		# readrlt=$?
# 		# if [ $readrlt -ne 0 ]; then
# 		# 	echo "跳过, 不是elf文件: $filename"
# 		# 	continue
# 		# fi

# 		elfinfo=`file $i 2>/dev/null`
		
# 		if [[ "$elfinfo" != *": ELF "* ]]; then
# 			echo "跳过, 不是elf文件: $filename"
# 			continue
# 		fi

# 		if [[ "$elfinfo" == *"relocatable"* ]]; then
# 			echo "跳过, 不是动态库或可执行文件: $filename"
# 			continue
# 		fi

# 		if [[ "$elfinfo" == *"statically linked"* ]]; then
# 			echo "跳过, 不是动态库或可执行文件: $filename"
# 			continue
# 		fi

# 		tmpmsg=""

# 		: '
# 		# echo "$elfinfo"|grep "interpreter" 2>&1 > /dev/null
# 		# if [ $? -eq 0 ]; then
# 		# 	tmpmsg+="有interpreter, "

# 		# 	# interpreter=${elfinfo##*interpreter}
# 		# 	# interpreter=${interpreter%%,*}
# 		# 	# # echo ${interpreter}

# 		# 	# if [ "${WBOX_INTERPRT}" != "" ]; then
# 		# 	# 	patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH} --set-interpreter ${WBOX_INTERPRT}   "$i"
# 		# 	# 	if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		# 	# else
# 		# 	# 	patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH}                                      "$i"
# 		# 	# 	if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		# 	# fi

# 		# else
# 		# 		tmpmsg+="无interpreter, "
# 		# 		# patchelf ${WBOX_FORCERPT} --set-rpath "\$ORIGIN"  "$i"
# 		# 		# if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		# fi
# 		'

# 		elfinfo=`readelf -d $i 2>/dev/null`
# 		if [[ "$elfinfo" == *"Library runpath:"* ]]; then
# 			tmpmsg+="有 runpath"
# 			tmprpath=`echo "$elfinfo"|grep "Library runpath:"`
# 			tmprpath=${tmprpath##*"Library runpath: ["}
# 			tmprpath=${tmprpath%%"]"*}

# 			tpath2zpath "$tmprpath"
# 			WBOX_RUN_PATH=$ZPATH

# 			echo "$filename  $tmprpath => ${WBOX_RUN_PATH}"

# 			WBOX_FORCERPT=
# 			patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH}  "$i"
# 			if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		else
# 			tmpmsg+="无 runpath"
# 		fi

# 		if [[ "$elfinfo" == *"Library rpath:"* ]]; then
# 			tmpmsg+="有 runpath"
# 			tmprpath=`echo "$elfinfo"|grep "Library rpath:"`
# 			tmprpath=${tmprpath##*"Library rpath: ["}
# 			tmprpath=${tmprpath%%"]"*}

# 			tpath2zpath "$tmprpath"
# 			WBOX_RUN_PATH=$ZPATH

# 			echo "$filename  $tmprpath => ${WBOX_RUN_PATH}"

# 			WBOX_FORCERPT="--force-rpath"
# 			patchelf ${WBOX_FORCERPT} --set-rpath ${WBOX_RUN_PATH}  "$i"
# 			if [ $? -ne 0 ]; then echo "处理失败 $filename"; fi
# 		else
# 			tmpmsg+="无 runpath"
# 		fi

# 		# echo "$tmpmsg $i"

# 	done

# }


# function old_doPatch() {
# 	: '
# 		ln -sf /data/data/com.zzvm/files/z/usr/glibc/lib/ld-linux-aarch64.so.1 ld.so
# 	'

# 	echo "old...."

# 	mkdir -p $WBOXDIR/usr/glibc/opt/package-manager 2>/dev/null

# 	chmod +x $WBOXDIR/usr/glibc/bin/box64
# 	chmod +x $WBOXDIR/usr/glibc/${WBOX_WINE}/bin/{wine,wineserver}
# 	patchelf --force-rpath \
# 	--set-rpath       ${APP_INTERNAL_DIR}/z/usr/glibc/lib \
# 	--set-interpreter ${APP_INTERNAL_DIR}/z/usr/glibc/lib/ld-linux-aarch64.so.1 \
# 	$WBOXDIR/usr/glibc/bin/box64

# 	sed -i "s|/data/data/com.termux/files/usr/tmp/.wine|/data/data/com.zzvm/files/z/usr/tmp/.wine|"							$WBOXDIR/usr/glibc/wine-9.3-vanilla-wow64/bin/wineserver
# 	sed -i "s|/data/data/com.termux/files/usr/tmp/.wine|/data/data/com.zzvm/files/z/usr/tmp/.wine|"							$WBOXDIR/usr/glibc/wine-9.3-vanilla-wow64/lib/wine/x86_64-unix/ntdll.so
# 	sed -i "s|/data/data/com.termux/files/usr/glibc/etc/bash.bashrc|/data/data/com.zzvm/files/z/usr/glibc/etc/bash.bashrc|"	$WBOXDIR/usr/glibc/bin/bash
# 	sed -i "s|/data/data/com.termux/files/usr/glibc/etc/resolv.conf|/data/data/com.zzvm/files/z/usr/glibc/etc/resolv.conf|"	$WBOXDIR/usr/glibc/lib/libc.so.6

# 	if [ "$QUICK_PATCH" != "1" ]; then
# 		echo "正在处理 termux (bionic libc 系列的软件)"
# 		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/lib
# 		WBOX_INTERPRT=
# 		WBOX_FORCERPT=
# 		old_wboxPatchElfFiles $WBOXDIR/usr/bin
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/apt
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/bash
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/cmake
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/engines-1.1
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/gawk
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/pkgconfig
# 		old_wboxPatchElfFiles $WBOXDIR/usr/lib/p7zip

# 		echo "正在处理 glibc  (gnu    libc 系列的软件)"
# 		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/glibc/lib:${APP_INTERNAL_DIR}/z/usr/glibc/lib/x86_64-linux-gnu/
# 		WBOX_INTERPRT=${APP_INTERNAL_DIR}/z/usr/glibc/lib/ld-linux-aarch64.so.1
# 		WBOX_FORCERPT="--force-rpath"
# 		old_wboxPatchElfFiles               $WBOXDIR/usr/glibc/bin
# 		# wboxPatchElfFiles $WBOXDIR/usr/glibc/lib	# 这个做了会报错，得专门处理
# 		# wbox_wine_elfheader_patch $WINE_PATH/bin	# 这个也不需要
# 	fi

# 		echo "正在处理 glibc  (gnu    libc 系列的动态库)"
# 		WBOX_RUN_PATH=${APP_INTERNAL_DIR}/z/usr/lib
# 		WBOX_INTERPRT=
# 		WBOX_FORCERPT=
# 		old_wboxPatchElfFiles_for_glibc_lib $WBOXDIR/usr/glibc/lib

# 	echo "patch 已完成"
# }


function doPatch() {
	doPatch_new
}
